<template>
	<div id="app">
	<div class="sales-board-intro">
        <h3>{{courseid}}课程</h3>
        <p>Python是一种跨平台的计算机程序设计语言。是一种面向对象的动态类型语言，最初被设计用于编写自动化脚本(shell)，随着版本的不断更新和语言新功能的添加，越来越多被用于独立的、大型项目的开发。</p>
      </div>
      <div class="sales-board-form">
      	     <div class="sales-board-line">
              <div class="sales-board-line-left">
                 产品单价：
              </div>
              <div class="sales-board-line-right">
                {{dprice}}
              </div>
          </div>
          <div class="sales-board-line">
              <div class="sales-board-line-left">
                  购买数量：
              </div>
              <div class="sales-board-line-right">
                <v-counter @on-change="onParamChange('buyNum', $event)"></v-counter>
              </div>
          </div>
          <div class="sales-board-line">
              <div class="sales-board-line-left">
                  产品类型：
              </div>
              <div class="sales-board-line-right">
                  <v-selection :selections="buyTypes" @on-change="onParamChange('buyType', $event)"></v-selection>
              </div>
          </div>
          <div class="sales-board-line">
              <div class="sales-board-line-left">
                  有效时间：
              </div>
              <div class="sales-board-line-right">
                  <v-chooser
                  :selections="periodList"
                  @on-change="onParamChange('period', $event)"></v-chooser>
              </div>
          </div>
          <div class="sales-board-line">
              <div class="sales-board-line-left">
                  总价：
              </div>
              <div class="sales-board-line-right">
                  {{ total}} 元
              </div>
          </div>
          <div class="sales-board-line">
              <div class="sales-board-line-left">&nbsp;</div>
              <div class="sales-board-line-right">
                  
                    <mt-button type="primary" size="small" @click="showPayDialog">立即购买</mt-button>
               
              </div>
          </div>
      </div>
   
      <my-dialog :is-show="isShowPayDialog" @on-close="hidePayDialog">
        <table class="buy-dialog-table">
          <tr>
            <th>数量</th>
            <th>类型</th>
            <th>有效时间</th>
            <th>版本</th>
            <th>总价</th>
          </tr>
          <tr>
            <td>{{ buyNum }}</td>
            <td>{{ buyType.label }}</td>
            <td>{{ period.label }}</td>
            <td>
              <span v-for="item in versions">{{ item.label }}</span>
            </td>
            <td>{{ zprice }}</td>
          </tr>
        </table>
        <!--<h3 class="buy-dialog-title">请选择银行</h3>
        <bank-chooser @on-change="onChangeBanks"></bank-chooser>-->
       
           <mt-button type="primary" size="small" @click="confirmBuy">确定购买</mt-button>
      
      </my-dialog>
      <my-dialog :is-show="isShowErrDialog" @on-close="hideErrDialog">
        支付失败！
      </my-dialog>
    <!--  <check-order :is-show-check-dialog="isShowCheckOrder" :order-id="orderId" @on-close-check-dialog="hideCheckOrder"></check-order>-->
	</div>
</template>

<script>
import VSelection from './base/selection'
import VCounter from './base/counter'
import VChooser from './base/chooser'
import VMulChooser from './base/multiplyChooser'
import Dialog from './dialog'
//import BankChooser from './bankChooser'
//import CheckOrder from './checkOrder'
import _ from 'lodash'
export default {
  components: {
    VSelection,
    VCounter,
    VChooser,
    VMulChooser,
    MyDialog: Dialog,
   // BankChooser,
  //  CheckOrder
  },
  data () {
    return {
    	courseid:'',
     dprice:200,
      buyNum: 0,
      buyType: {},
      versions: [],
      period: {},
      zprice: 0,
      versionList: [
        {
          label: '客户版',
          value: 0
        },
        {
          label: '代理商版',
          value: 1
        },
        {
          label: '专家版',
          value: 2
        }
      ],
      periodList: [
        {
          label: '半年',
          value: 0
        },
        {
          label: '一年',
          value: 1
        },
        {
          label: '三年',
          value: 2
        }
      ],
      buyTypes: [
        {
          label: '入门版',
          value: 0
        },
        {
          label: '中级版',
          value: 1
        },
        {
          label: '高级版',
          value: 2
        }
      ],
      isShowPayDialog: false,
      bankId: null,
      orderId: null,
      isShowCheckOrder: false,
      isShowErrDialog: false
    }
  },
  created(){
  	let id=this.$route.query.id;
  	return id;
  },
  methods: {
    onParamChange (attr, val) {
      this[attr] = val
     // this.getPrice()
    },
//  getPrice () {
//    let buyVersionsArray = _.map(this.versions, (item) => {
//      return item.value
//    })
//    let reqParams = {
//      buyNumber: this.buyNum,
//      buyType: this.buyType.value,
//      period: this.period.value,
//      version: buyVersionsArray.join(',')
//    }
//    this.$axios.post('../../static/db.json', reqParams)
//    .then((res) => {
//      this.dprice = res.data.amount
//    })
//  },
    showPayDialog () {
      this.isShowPayDialog = true
    },
    hidePayDialog () {
      this.isShowPayDialog = false
    },
    hideErrDialog () {
      this.isShowErrDialog = false
    },
    hideCheckOrder () {
      this.isShowCheckOrder = false
    },
    onChangeBanks (bankObj) {
      this.bankId = bankObj.id
    },
    confirmBuy () {
//    let buyVersionsArray = _.map(this.versions, (item) => {
//      return item.value
      
//    })
//    let reqParams = {
//      buyNumber: this.buyNum,
//      buyType: this.buyType.value,
//      period: this.period.value,
//      version: buyVersionsArray.join(','),
//      bankId: this.bankId
//    }
//    this.$http.post('/api/createOrder', reqParams)
//    .then((res) => {
//      this.orderId = res.data.orderId
//      this.isShowCheckOrder = true
//      this.isShowPayDialog = false
//    }, (err) => {
//      this.isShowBuyDialog = false
//      this.isShowErrDialog = true
//    })
 this.isShowPayDialog=false
    }
  },
  mounted () {
    this.buyNum = 1
    this.buyType = this.buyTypes[0]
    this.versions = [this.versionList[0]]
    this.period = this.periodList[0]
    this.courseid=this.$route.query.id
    //this.getPrice()
  },
  computed:{
  	total(){
  		return this.zprice=this.dprice*this.buyNum
  	}
  }
}
</script>

<style scoped>
.buy-dialog-title {
  font-size: 12px;

}
.buy-dialog-btn {
  margin-top: 20px;
}
.buy-dialog-table {
  width: 100%;
  margin-top: 20px;
  margin-bottom: 20px;
}
.buy-dialog-table td,
.buy-dialog-table th{
  border: 1px solid #e3e3e3;
  text-align: center;
  padding: 5px 0;
   font-size: 14px;
}
.buy-dialog-table th {
  background: #4fc08d;
  color: #fff;
  border: 1px solid #4fc08d;
  font-weight: normal;
    font-size: 14px;
}
.detail-wrap {
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
  padding-top: 20px;
}
.detail-left {
  float: left;
  width: 200px;
  text-align: center;
}
.detail-right {
  float: left;
  width: 300px;
  margin-left: 20px;
}
.product-board {
  background: #fff;
  padding: 20px 0;
}
.product-board ul {
  margin-top: 20px;
}
.product-board li {
  text-align: left;
  padding: 10px 15px;
  cursor: pointer;
}
.product-board li.active,
.product-board li:hover {
  background: #4fc08d;
  color: #fff;
}
.product-board li a {
  display: block;
}
.sales-board {
  background: #fff;
}
.sales-board-form {

}
.sales-board-intro h3 {
  font-size: 20px;
  padding: 20px;
}
.sales-board-intro p {
  background: #f7fcff;
  padding: 10px 20px;
  color: #999;
  line-height: 1.8;
}
.sales-board-form {
  padding: 30px 20px;
  font-size: 14px;
}
.sales-board-line {
  clear: both;
  padding-bottom: 20px;
}
.sales-board-line-left {
    display: inline-block;
    width: 100px;
}
.sales-board-line-right {
    display: inline-block;
    width:200px;
}
.sales-board-des {
  border-top: 20px solid #f0f2f5;
  padding: 15px 20px;
}
.sales-board-des p {
  line-height: 1.6;
}
.sales-board-des h2 {
  font-size: 20px;
  padding-bottom: 15px;
}
.sales-board-des h3 {
  font-size: 18px;
  font-weight: bold;
  padding: 20px 0 10px 0;
}
.sales-board-des li {
  padding: 5px 0;
}
.sales-board-table {
  width: 100%;
  margin-top: 20px;
}
.sales-board-table th {
  background: #4fc08d;
  color: #fff;
}
.sales-board-table td {
    border: 1px solid #f0f2f5;
    padding: 15px;
}
</style>